package com.crscd.ai.controller;

import com.crscd.ai.records.StudentRecord;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 9/30/25 4:42 PM
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
public class StructuredOutputController {
  @Resource(name = "qwenChatClient")
  private ChatClient qwenChatClient;

  @GetMapping("/structuredoutput/chat")
  public StudentRecord chat(
      @RequestParam(name = "sname") String sname, @RequestParam(name = "email") String email) {
    return qwenChatClient
        .prompt()
        .user(
            spec -> {
              spec.text("学号1001,我叫{sname}，大学专业计算机科学与技术，邮箱{email}")
                  .param("sname", sname)
                  .param("email", email);
            })
        .call()
        .entity(StudentRecord.class);
  }

  @GetMapping("/structuredoutput/chat2")
  public StudentRecord chat2(
      @RequestParam(name = "sname") String sname, @RequestParam(name = "email") String email) {
    String stringTemplate = "学号1002,我叫{sname}，大学专业软件工程，邮箱{email}";
    return qwenChatClient
        .prompt()
        .user(spec -> spec.text(stringTemplate).param("sname", sname).param("email", email))
        .call()
        .entity(StudentRecord.class);
  }
}
